package de.tsajar.es.physics;

import com.jme3.app.Application;
import com.jme3.app.state.AppStateManager;
import de.tsajar.es.position.PositionComponent;
import com.jme3.math.Vector3f;
import com.simsilica.es.Entity;
import com.simsilica.es.EntitySet;
import de.tsajar.es.EntitySystemAppState;

/**
 *
 * @author Eike Foede
 */
public class SimpleMovementSystem extends EntitySystemAppState{

    private EntitySet es;

    @Override
    public void initialize(AppStateManager stateManager, Application app) {
        super.initialize(stateManager, app); 
        es = ed.getEntities(VelocityComponent.class, PositionComponent.class);
    }

    @Override
    public void update(float tpf) {
        es.applyChanges();
        for (Entity e : es) {
            Vector3f position = e.get(PositionComponent.class).getPosition();
            Vector3f velocity = e.get(VelocityComponent.class).getVelocity();
            e.set(new PositionComponent(position.add(velocity.mult(tpf))));
        }
    }
}
